<template>
	<view class="address_item_com">
		<view class="add_info" @click="update">
			<view class="top">
				<view class="user_name u-line-1">{{value.consignee}}</view>
				<view class-="user_name u-line-1">{{ value.postcode }}</view>
				<view class="user_phone u-line-1">{{value.mobile}}</view>
			</view>
			<view class="addres u-line-1">
				{{ value.region }} {{value.provName}}{{value.cityName}}{{value.areaName}}{{value.address}}
			</view>
		</view>
		<view class="add_operation">
			<u-radio-group size="36" v-model="value.defaultType">
				<u-radio label-size="26" @change="radioChange" :name="1">{{$t("locales.default")}}</u-radio>
			</u-radio-group>
			<view class="del_btn" @click="delAddres">
				<u-icon name="trash" size="28"></u-icon>
				<text class="_text">{{$t("locales.delete")}}</text>
			</view>
		</view>
	</view>
</template>

<script>
import { addressList, setDefaultAddre, deleteUserAddress } from '@/api/http/user'
export default {
	data() {
		return {}
	},
	props: {
		value: {
			type: Object,
			default: () => {}
		}
	},
	methods: {
		radioChange(e) {
			// 调用修改默认地址
			setDefaultAddre({id: this.value.id}).then(res => {
				if (res.code === 200) {
					this.$emit('change')
				} else {
					uni.showToast({
						icon: 'none',
						title: res.message
					})
				}
			})
		},
			
		delAddres() {
			// 调用删除地址
			deleteUserAddress({id: this.value.id}).then(res => {
				if (res.code === 200) {
					this.$emit('change')
				} else {
					uni.showToast({
						icon: 'none',
						title: res.message
					})
				}
			})
		},
		
		update() {
			uni.navigateTo({
				url: '/pages/user/address/newAddress?id=' + this.value.id
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.address_item_com {
	margin-top: 20rpx;
	background-color: #ffffff;
	padding: 0 22rpx;
	padding-top: 10rpx;
	box-sizing: border-box;
	color: $u-main-color;
	.add_info {
		border-bottom: 1px solid #eeeeee;
		.top {
			display: flex;
			justify-content: space-between;
			line-height: 80rpx;
			.user_name {
				font-size: $uni-font-size-base;
				width: 300rpx;
			}
			.user_phone {
				width: 300rpx;
				font-size: $uni-font-size-sm;
				text-align: right;
			}
		}
		.addres {
			color: $u-type-info;
			line-height: 80rpx;
		}
	}
	.add_operation {
		height: 93rpx;
		align-items: center;
		display: flex;
		justify-content: space-between;
		.del_btn {
			height: 90rpx;
			line-height: 90rpx;
			._text {
				display: inline-block;
				margin-left: 10rpx;
				color: #555;
			}
		}
	}
}
</style>
